package com.mlk.engUser.tonglian;

import cn.hutool.core.util.XmlUtil;

public class Tranx200004 {

	public static void main(String[] args) {
        test();
//		InfoReq infoReq = DemoUtil.makeReq("200004");
//		TransQueryReq queryReq = new TransQueryReq();
//		queryReq.setMERCHANT_ID(DemoConfig.merchantid);
//		// 200604000007235-0001567128103110
//		queryReq.setQUERY_SN("200452000018293-0001567578779563");///查询交易的文件名
//		/*queryReq.setSTART_DAY("");
//		queryReq.setEND_DAY("");*/
//		AipgReq req = new AipgReq();
//		req.setINFO(infoReq);
//		req.addTrx(queryReq);
//
//		try{
//			//step1 对象转xml
//			String xml = XmlParser.toXml(req);
//			//step2 加签
//			String signedXml = DemoUtil.buildSignedXml(xml);
//			//step3 发往通联
//			String url = DemoConfig.url+"?MERCHANT_ID="+DemoConfig.merchantid+"&REQ_SN="+infoReq.getREQ_SN();
//			System.out.println("============================请求报文============================");
//			System.out.println(signedXml);
//			String respText = HttpUtil.post(signedXml, url);
//			System.out.println("============================响应报文============================");
//			System.out.println(respText);
//			//step4 验签
//			if(!DemoUtil.verifyXml(respText)){
//				System.out.println("====================================================>验签失败");
//				return;
//			}
//			System.out.println("====================================================>验签成功");
//			//step5 xml转对象
//			AipgRsp rsp = XmlParser.parseRsp(respText);
//			InfoRsp infoRsp = rsp.getINFO();
//			System.out.println(infoRsp.getRET_CODE());
//			System.out.println(infoRsp.getERR_MSG());
//			if("0000".equals(infoRsp.getRET_CODE())){
//				QTransRsp ret = (QTransRsp) rsp.trxObj();
//				@SuppressWarnings("unchecked")
//                List<QTDetail> list = ret.getDetails();
//				for(QTDetail dt : list){
//					System.out.println(dt.getRET_CODE());
//					System.out.println(dt.getERR_MSG());
//				}
//			}
//		}catch(AIPGException e){
//			e.printStackTrace();
//		}
	}

	public static void test(){
        String str = "<?xml version=\"1.0\" encoding=\"GBK\"?><AIPG>\n" +
                "  <INFO>\n" +
                "    <TRX_CODE>100002</TRX_CODE>\n" +
                "    <VERSION>04</VERSION>\n" +
                "    <DATA_TYPE>2</DATA_TYPE>\n" +
                "    <LEVEL>5</LEVEL>\n" +
                "    <MERCHANT_ID>200604000007235</MERCHANT_ID>\n" +
                "    <USER_NAME>20060400000723504</USER_NAME>\n" +
                "    <USER_PASS>111111</USER_PASS>\n" +
                "    <REQ_SN>200604000007235-0001567503731122</REQ_SN>\n" +
                "    <SIGNED_MSG>7f781085ab912209232a98a8f1a4262df15c9aeb390ebc51463e93fca43bad25fd34551c3d7f9b2350f04a721660872c6677e5fd01ed5a46320be94e4e932a25f22b5d896e3e37b6f3ce854288f40a352d1e1d9c805a7a14e22b3ad433a2146bdaadf68079072fc66bfbd67ec5a7f02cfc60c7724292feb873fa753fdc587afe</SIGNED_MSG>\n" +
                "  </INFO>\n" +
                "  <BODY>\n" +
                "    <TRANS_SUM>\n" +
                "      <BUSINESS_CODE>09900</BUSINESS_CODE>\n" +
                "      <MERCHANT_ID>200604000007235</MERCHANT_ID>\n" +
                "      <SUBMIT_TIME></SUBMIT_TIME>\n" +
                "      <TOTAL_ITEM>1</TOTAL_ITEM>\n" +
                "      <TOTAL_SUM>10</TOTAL_SUM>\n" +
                "      <SETTDAY></SETTDAY>\n" +
                "    </TRANS_SUM>\n" +
                "    <TRANS_DETAILS>\n" +
                "      <TRANS_DETAIL>\n" +
                "        <SN>1</SN>\n" +
                "        <E_USER_CODE></E_USER_CODE>\n" +
                "        <BANK_CODE>0105</BANK_CODE>\n" +
                "        <ACCOUNT_TYPE></ACCOUNT_TYPE>\n" +
                "        <ACCOUNT_NO>6217002340032656607</ACCOUNT_NO>\n" +
                "        <ACCOUNT_NAME>胡宁涛</ACCOUNT_NAME>\n" +
                "        <PROVINCE></PROVINCE>\n" +
                "        <CITY></CITY>\n" +
                "        <BANK_NAME></BANK_NAME>\n" +
                "        <ACCOUNT_PROP>0</ACCOUNT_PROP>\n" +
                "        <AMOUNT>10</AMOUNT>\n" +
                "        <CURRENCY>CNY</CURRENCY>\n" +
                "        <PROTOCOL></PROTOCOL>\n" +
                "        <PROTOCOL_USERID></PROTOCOL_USERID>\n" +
                "        <ID_TYPE></ID_TYPE>\n" +
                "        <ID></ID>\n" +
                "        <TEL></TEL>\n" +
                "        <CUST_USERID></CUST_USERID>\n" +
                "        <REMARK></REMARK>\n" +
                "        <SETTACCT></SETTACCT>\n" +
                "        <SETTGROUPFLAG></SETTGROUPFLAG>\n" +
                "        <SUMMARY></SUMMARY>\n" +
                "        <UNION_BANK></UNION_BANK>\n" +
                "        <FEEFLAG></FEEFLAG>\n" +
                "      </TRANS_DETAIL>\n" +
                "    </TRANS_DETAILS>\n" +
                "  </BODY>\n" +
                "</AIPG>";
        System.out.println(XmlUtil.parseXml(str).getElementsByTagName("ACCOUNT_NAME").item(0).getTextContent());
    }
}